<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>数组排序(从大到小)</title>
</head>

<body>
    <script>
        function sort(array) {
            for (var i = 1; i < arr.length; i++) {
                var isSort = true;
                for (var j = 0; j < arr.length - i; j++) {
                    if (arr[j] < arr[j + 1]) {
                        tmp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = tmp;
                        isSort = false;
                    }
                }
                if (isSort) {
                    break;
                }
            }
            return arr;
        }
        var arr = [10, 15, 5, 8, 7, 12];
        alert(sort(arr));
    </script>
</body>

</html>